//------------------------------------------------------------------------------
// <copyright file="WindowOptions.xaml.cs" company="Damian Antonowicz">
//       copyright © 2010 Damian Antonowicz
// </copyright>
// <author>Damian Antonowicz</author>
// <email>poczta@damianantonowicz.pl</email>
//------------------------------------------------------------------------------

using System;
using System.Collections.Generic;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Input;
using DotBeer.Data.Properties;
using DAnton.Utilities.Extensions;
using System.Windows.Documents;
using System.Windows.Data;
using System.ComponentModel;
using System.Diagnostics;
using DotBeer.UI.WPFClient.ViewModels;

namespace DotBeer.UI.WPFClient
{
    /// <summary>
    /// Interaction logic for WindowOptions.xaml
    /// </summary>
    public partial class WindowOptions : Window
    {
        OptionsWindowViewModel viewModel;
        bool isClosing = false;

        public WindowOptions()
        {
            InitializeComponent();

            // Bad hack. Need to be changed.
            this.Loaded += new RoutedEventHandler(WindowOptions_Loaded);

        }

        void WindowOptions_Loaded(object sender, RoutedEventArgs e)
        {
            this.viewModel = this.DataContext as OptionsWindowViewModel;
            this.viewModel.CloseViewRequested += new EventHandler(viewModel_CloseViewRequested);

            this.Closing += new CancelEventHandler(WindowOptions_Closing);
        }

        private void viewModel_CloseViewRequested(object sender, EventArgs e)
        {
            if (!this.isClosing)
                this.Close();
        }

        private void WindowOptions_Closing(object sender, CancelEventArgs e)
        {
            this.isClosing = true;
            this.viewModel.HandleViewClosing();
        }
    }
}
